package com.liu.algorithm.search.slidingWindow;


/**
 * 给你两个字符串 s1 和 s2 ，写一个函数来判断 s2 是否包含 s1 的排列。如果是，返回 true ；否则，返回 false 。
 */
public class Leetcode567 {
    public static void main(String[] args) {
        Leetcode567 obj = new Leetcode567();
        String s1 = "ab";
        String s2 = "eidbaooo";
        System.out.println(obj.checkInclusion(s1, s2));
    }

    public boolean checkInclusion(String s1, String s2) {
        int length = s1.length();
        int left = 0;
        int right = length - 1;
        while (right < s2.length()) {
            String temp = s2.substring(left, right);
            left = right;
            right += s1.length();
            if (s1.equals(temp)) {
                return true;
            } else {
                boolean b = true;
                for (int i = 0; i < length; i++) {
                    String s11 = s1.substring(i, i + 1);
                    String s21 = temp.substring(length - i - 2, length - i - 1);
                    System.out.println(s11 + "~" + s21);
                    if (!s11.equals(s21)) {
                        b = false;
                        break;
                    }
                }
                if (b) {
                    return true;
                }
            }
        }
        return false;
    }
}
